<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      :title="`生成账单结转`"
      :visible.sync="visible"
      width="410px"
      @closed="reset"
    >
      <div class="page">
        <el-form ref="dataForm" :rules="rules" :model="dataForm" label-position="left" label-width="100px">
          <el-form-item label="结转时间:" class="block" prop="happendDt">
            <el-date-picker
              v-model="dataForm.happendDt"
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              :clearable="false"
              style="width: 230px;"
              :picker-options="pickerOptions"
            />
          </el-form-item>
          <el-form-item label="站点" class="block" prop="orgId">
            <el-tree-select
              v-model="dataForm.orgId"
              clearable
              class="tree-select"
              :popover-width="360"
              :select-params="{
                clearable: true,
                placeholder: '请选择',
                loading: $loadingPlugin.getTreeData
              }"
              :tree-params=" {
                'expand-on-click-node': false,
                'highlight-current': true,
                'filterable': true,
                props:{
                  value:'orgId',
                  label: 'orgName',
                  disabled: 'disabled',
                },
                data: treeData
              }"
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="$loadingPlugin.cancel" type="danger" @click="cancel('dataForm')">
          取消
        </el-button>
        <el-button :loading="$loadingPlugin.submit" type="primary" @click="sumbit('dataForm')">
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { billCarrySave } from '@/api'
  //   import { formatColumnMap, parseTime } from '@/utils'

  export default {
    components: {
    },
    props: {
      treeData: {
        type: Array,
        default: []
      }
    },
    data() {
      return {
        visible: false,
        title: '新增',
        dataForm: {},
        rules: {
          happendDt: [{ required: true, message: '请选择结转时间', trigger: 'change' }],
          orgId: [{ required: true, message: '请选择站点', trigger: 'change' }]
        },
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e7
          }
        }
      }
    },
    computed: {

    },
    watch: {

    },
    mounted() {

    },
    destroyed() {

    },
    methods: {
      open(temp) {
        return new Promise(resolve => {
          this.resolve = resolve
          if (temp) {
            this.dataForm = temp
            // console.log(temp)
          }
          this.visible = true
        })
      },
      // 取消
      async cancel() {
        this.resolve()
        await this.reset()
        this.visible = false
      },
      // 保存
      sumbit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // console.log(form)
            const params = { ...this.dataForm }
            this.submit(params)
          } else {
            return false
          }
        })
      },
      async submit(params) {
        await billCarrySave(params)
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '新增成功!',
          type: 'success',
          duration: 2000
        })
      },
      reset() {
        this.dataForm = {}
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      }
    }
  }
</script>

<style lang='scss' scoped>
</style>
